{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2024-04-12T08:59:52.831816Z",
     "start_time": "2024-04-12T08:59:52.827621Z"
    }
   },
   "source": [
    "import numpy as np\n",
    "import torch\n",
    "\n",
    "TAS_pulsewidth = np.arange(3, 65, 5)\n",
    "print(TAS_pulsewidth)"
   ],
   "outputs": []
  },
  {
   "cell_type": "markdown",
   "source": [],
   "metadata": {
    "collapsed": false
   },
   "id": "c8a9627b81820f48"
  },
  {
   "cell_type": "code",
   "source": [
    "from scipy.io import loadmat\n",
    "from sklearn.svm import SVC\n",
    "from sklearn.model_selection import train_test_split\n",
    "from sklearn.metrics import confusion_matrix, ConfusionMatrixDisplay\n",
    "import matplotlib.pyplot as plt\n",
    "dictdata = loadmat(\"traindata_20dB.mat\")\n",
    "dataload = dictdata['traindata']\n",
    "dataload = dataload[:1000]\n",
    "X = dataload[:, :8]\n",
    "y = dataload[:, 8]\n",
    "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=42)\n",
    "svm_model = SVC(kernel='linear', probability=True)\n",
    "svm_model.fit(X_train, y_train)\n",
    "y_pred = svm_model.predict(X_test)\n",
    "acc = svm_model.score(X_test, y_test)\n",
    "cm = confusion_matrix(y_test, y_pred)\n",
    "disp = ConfusionMatrixDisplay(confusion_matrix=cm)\n",
    "disp.plot(cmap=plt.cm.Blues)\n",
    "plt.title('Confusion Matrix')\n",
    "plt.savefig('SVMConfusionMatrix.png')\n",
    "plt.show()\n",
    "print(acc)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-05-26T13:24:26.097390Z",
     "start_time": "2024-05-26T13:24:25.852082Z"
    }
   },
   "id": "a81add5dfe311b65",
   "execution_count": 2,
   "outputs": []
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-22T08:37:33.896762Z",
     "start_time": "2024-05-22T08:37:29.313168Z"
    }
   },
   "cell_type": "code",
   "source": [
    "from protonet import PrototypicalNetwork\n",
    "from torchviz import make_dot\n",
    "import torch\n",
    "net = PrototypicalNetwork(64, 256, 64)\n",
    "input = torch.rand(150, 64)\n",
    "output = net(input)\n",
    "graph = make_dot(output, params=dict(net.named_parameters()))\n",
    "graph.render(\"Multi_Scale_ResNet\",format='png')"
   ],
   "id": "2203f1def597669b",
   "execution_count": 1,
   "outputs": []
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "",
   "id": "a184806577156b3e"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-26T06:53:41.447426Z",
     "start_time": "2024-05-26T06:53:41.177028Z"
    }
   },
   "cell_type": "code",
   "source": [
    "import matplotlib.pyplot as plt\n",
    "\n",
    "# 读取日志文件\n",
    "def read_log_file(log_file):\n",
    "    epochs = []\n",
    "    losses = []\n",
    "    accuracies = []\n",
    "\n",
    "    with open(log_file, 'r') as f:\n",
    "        for line in f:\n",
    "            if 'Epoch' in line and 'Loss' in line and 'Accuracy' in line:\n",
    "                parts = line.strip().split(', ')\n",
    "                epoch = int(parts[0].split()[1])\n",
    "                loss = float(parts[1].split()[1])\n",
    "                accuracy = float(parts[2].split()[1])\n",
    "                epochs.append(epoch)\n",
    "                losses.append(loss)\n",
    "                accuracies.append(accuracy)\n",
    "\n",
    "    return epochs, losses, accuracies\n",
    "\n",
    "# 示例用法\n",
    "log_file = \"training_log.txt\"\n",
    "epochs, losses, accuracies = read_log_file(log_file)\n",
    "\n",
    "# 打印结果以验证\n",
    "print(\"Epochs:\", epochs)\n",
    "print(\"Losses:\", losses)\n",
    "print(\"Accuracies:\", accuracies)\n"
   ],
   "id": "155dea6de3723243",
   "execution_count": 1,
   "outputs": []
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2024-05-26T06:54:30.157311Z",
     "start_time": "2024-05-26T06:54:29.973973Z"
    }
   },
   "cell_type": "code",
   "source": [
    "def plot_results(epochs, losses, accuracies):\n",
    "    fig, ax1 = plt.subplots()\n",
    "\n",
    "    ax1.set_xlabel('Epoch')\n",
    "    ax1.set_ylabel('Loss', color='tab:blue')\n",
    "    ax1.plot(epochs, losses, color='tab:blue', label='Loss')\n",
    "    ax1.tick_params(axis='y', labelcolor='tab:blue')\n",
    "\n",
    "    ax2 = ax1.twinx()  # instantiate a second axes that shares the same x-axis\n",
    "    ax2.set_ylabel('Accuracy', color='tab:green')  # we already handled the x-label with ax1\n",
    "    ax2.plot(epochs, accuracies, color='tab:green', label='Accuracy')\n",
    "    ax2.tick_params(axis='y', labelcolor='tab:green')\n",
    "\n",
    "    fig.tight_layout()  # otherwise the right y-label is slightly clipped\n",
    "    plt.title('Training Loss and Accuracy')\n",
    "    plt.show()\n",
    "\n",
    "# 示例用法\n",
    "plot_results(epochs, losses, accuracies)\n"
   ],
   "id": "c3e719576cbb045f",
   "execution_count": 2,
   "outputs": []
  },
  {
   "metadata": {},
   "cell_type": "code",
   "source": [
    "file_path = \"D:\\\\PC_Sample2\\\\PC_Test_Data2.txt\"\n",
    "with open(file_path, 'r', encoding='utf-8') as f:\n",
    "    lines = f.readlines()\n",
    "    line_count = len(lines)\n",
    "    print(f\"文件 '{file_path}' 中有 {line_count} 行。\")"
   ],
   "id": "ce43052cbbf908fe",
   "execution_count": 3,
   "outputs": []
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-04-19T09:04:35.549617Z",
     "start_time": "2025-04-19T09:04:34.869059Z"
    }
   },
   "cell_type": "code",
   "source": [
    "n, m = map(int, input().split())\n",
    "orders = [tuple(map(int, input().split())) for _ in range(n)]\n",
    "orders.sort(key=lambda x: x[0] + x[1])  # 简单排序策略\n",
    "used = set()\n",
    "count = 0\n",
    "for a, b in orders:\n",
    "    if a not in used and b not in used:\n",
    "        used.update([a, b])\n",
    "        count += 1\n",
    "print(count)"
   ],
   "id": "ad9d0040efc818f5",
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'python' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001B[1;31m---------------------------------------------------------------------------\u001B[0m",
      "\u001B[1;31mNameError\u001B[0m                                 Traceback (most recent call last)",
      "Cell \u001B[1;32mIn[3], line 1\u001B[0m\n\u001B[1;32m----> 1\u001B[0m python\n\u001B[0;32m      2\u001B[0m 复制代码\n\u001B[0;32m      3\u001B[0m \u001B[38;5;28;01mimport\u001B[39;00m \u001B[38;5;21;01msys\u001B[39;00m\n",
      "\u001B[1;31mNameError\u001B[0m: name 'python' is not defined"
     ]
    }
   ],
   "execution_count": 3
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": "",
   "id": "ed24107e4b031239"
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
